<template>
  <div class="newsinfo-container">
    <!-- 大标题 -->
    <span class="title">{{ newsInfo.title }}</span>
    <!-- 子标题 -->
    <p class="subtitle">
      <span>发表时间:{{ newsInfo.add_time | dateFormat }}</span>
      <span>点击次数 {{ newsInfo.click }} 次</span>
    </p>
    <hr>
    <!-- 内容区域 -->
    <div class="content" v-html="newsInfo.content"></div>
    <!-- 评论区域 -->
    <comment-box :id=this.id></comment-box>
  </div>
</template>

<script>
import axios from 'axios'
import { Toast } from 'mint-ui'
// 引入子组件
import commtent from '../subComments/comment.vue'

export default{
  data () {
    return {
      id: this.$route.params.id,
      newsInfo: {}
    }
  },
  created () {
    this.getNewsInfo()
  },
  methods: {
    getNewsInfo () {
      axios.get('http://localhost:8080/api/newsInfo/' + this.id).then(result => {
        if (result.status === 200) {
          this.newsInfo = result.data
        } else {
          Toast('数据获取失败')
        }
      })
    }
  },
  components: {
    'comment-box': commtent
  }
}
</script>

<style>
  .newsinfo-container img{
    width:100%;
  }
  .newsinfo-container{
    padding:0 4px;
  }
  .newsinfo-container .title{
    font-size: 16px;
    text-align: center;
    margin:15px 0;
    color: red;
  }
  .newsinfo-container .subtitle{
    font-size: 13px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
</style>
